<?php 
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of IndexController
*
*/

class Admin_UserController extends Zend_Controller_Action
{

	public function init(){
		$registry = Zend_Registry::getInstance();
		$this->_db = $registry->get('db');
	}
	 
    public function indexAction()
    {
		$this->_helper->layout()->disableLayout();
        //$this->_helper->viewRenderer->setNoRender(true);
        Zend_Loader::loadFile('../application/admin/models/User.php');
        
		$user_model = new User();
		$view_users = $user_model->viewUsers();
        
		$this->view->view_users = $view_users;        
    }   
	
	public function adduserAction()
	{
		$this->_helper->layout()->disableLayout();
	    Zend_Loader::loadFile('../application/admin/forms/User.php');
		Zend_Loader::loadFile('../application/admin/models/User.php');
		$user_model = new User();
		$request = $this->getRequest();
		$user_form = new Form_User();
		$this->view->user_form = $user_form;		
	}
	
	public function doadduserAction()
	{
		Zend_Loader::loadFile('../application/admin/forms/User.php');
		Zend_Loader::loadFile('../application/admin/models/User.php');
		$form_user = new Form_User();
		$request = $this->getRequest();
		
		if ($this->getRequest()->isPost()) {            
			$user_model = new User();
			$form_values = $request->getPost();
			$add_user = $user_model->addUser($form_values);			
		}
		
		exit;
	}

	public function edituserAction()
	{
		$this->_helper->layout()->disableLayout();
        //$this->_helper->viewRenderer->setNoRender(true);
	    Zend_Loader::loadFile('../application/admin/models/User.php');		
		$request = $this->getRequest();
		$userid = $request->getParam('userid');
		$this->view->userid = $userid;
		$user_model = new User();
		$getUserDetails = $user_model->viewUsersById($userid);
		$this->view->getUserDetails = $getUserDetails;		
	}
	
	public function doedituserAction()
	{
		Zend_Loader::loadFile('../application/admin/forms/User.php');
		Zend_Loader::loadFile('../application/admin/models/User.php');		
		$this->_helper->layout->setLayout('admin');
		$form_user = new Form_User();
		$request = $this->getRequest();
		$userid = $request->getParam('userid');
		if ($this->getRequest()->isPost()) {            
			$user_model = new User();
			$form_values = $request->getPost();
			$update_user = $user_model->updateUser($form_values, $userid);	
			if($update_user)
			{
				$this->_helper->redirector('index');
			}
		}
		
		exit;
	}
	
	public function deleteuserAction()
	{
		$this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
	    Zend_Loader::loadFile('../application/admin/models/User.php');	
		$request = $this->getRequest();
		$user_arr = $request->getParam('user_arr');
		$user_model = new User();
		$del_user = $user_model->deleteUser($user_arr);
		//$this->_helper->redirector('index');
	}
	
	public function editpassAction()
	{
		$this->_helper->layout()->disableLayout();
		$userid = $this->_getParam('userid', 0);
		$this->view->userid = $userid;
	}
	
	public function doeditpwdAction()
	{
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/User.php');	
	    $request = $this->getRequest();
	    $userid = $request->getParam('userid');
	    $curr_pwd = $request->getParam('curr_pwd');
	    $new_pwd = $request->getParam('new_pwd');
        $mod_user = new User();
        $change_pwd = $mod_user->updateAdminPassword($userid, $curr_pwd, $new_pwd);
        exit;	   
    }
}
?>
